package fire;
import java.util.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class FireHelper{

  public static String[] watchList = {"fire_m","fire_n"};
  public static ArrayList<String> condList = new ArrayList<String>(); 
  public static ArrayList<String> paramList = new ArrayList<String>();
  public static Node root;
 
  public static int fire_ackermann(int fire_m,int fire_n, Node parent){

    int counter = 0;
    int temp; 
    Node a = new Node();
    Fire.setTotalSteps(Fire.getTotalSteps() + 2);
    if(parent != null)
    {
      parent.addChild(a);
      a.setDepth(parent.getDepth() + 1); 
      if(a.getDepth() > Fire.getMaxDepth())
      {
        Fire.setMaxDepth(a.getDepth());
      }
      a.setParent(parent);
    }
    else
    {
        root = a;
        a.setDepth(0);
        
    }
     
     
    if(fire_m==0)
    {
      
      a.setCall(condList.get(counter) + " VALUES:" +  " fire_m=" + fire_m + " fire_n=" + fire_n );
      temp = fire_n+1; 
      a.setRetVal(String.valueOf(temp));
      return temp; 
    }
    counter++;
     
    if(fire_n==0)
    {
      
      a.setCall(condList.get(counter) + " VALUES:" +  " fire_m=" + fire_m + " fire_n=" + fire_n );
      temp = fire_ackermann(fire_m-1,1,a); 
      a.setRetVal(String.valueOf(temp));
      return temp; 
    }
    counter++;
     
    a.setCall(condList.get(counter) + " VALUES:" +  " fire_m=" + fire_m + " fire_n=" + fire_n );
    temp = fire_ackermann(fire_m-1,fire_ackermann(fire_m,fire_n-1,a),a); 
    a.setRetVal(String.valueOf(temp));
    return temp;
     
  }
  
  public static void doRecursive(Object[] params) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
  {
    Class c = Class.forName("fire.FireHelper");
    Method[] m = c.getDeclaredMethods();
    Object i = c.newInstance();
    System.out.println(m[1].toGenericString());
    
    m[1].invoke(i, params);
    
  }
  
    
   /**GUI HELPER FUNCTIONS**/
   public static void buildCondList(){ 
  
    condList.add("{m == 0} n + 1");
    condList.add("{n == 0} ackermann(m - 1, 1)");
    condList.add("{} ackermann(m - 1, ackermann(m, n - 1))");
  }
  
  
  public static void buildParamList(){
  
    paramList.add("int");
    paramList.add("int");
  
  }
  
  public static void makeLists(){
    buildCondList(); 
    buildParamList();
  }
  

  
}